/** 业务类型*/
export class BizType {
    bizId: number;
    bizCode: number;
    bizName: string;
    bizDesc: string;
    displayOrder: number;
    createTime: string;
    createUser: string;
    constructor(options: {
        bizId?: number,
        bizCode?: number,
        bizName?: string,
        bizDesc?: string,
        displayOrder?: number,
        createTime?: string,
        createUser?: string
    }) {
        this.bizId = options.bizId;
        this.bizCode = options.bizCode;
        this.bizName = options.bizName;
        this.bizDesc = options.bizDesc;
        this.displayOrder = options.displayOrder;
        this.createTime = options.createTime;
        this.createUser = options.createUser;
    }
}
/**流程定义 */
export class ProcDef {
    procDefId: number;
    procDefName: string;
    procDesc: string;
    bizId: number;
    bizName: string;
    timeStrategy: number;
    timeUnitId: number;
    timeUnitName: string;
    timeWarn: number;
    timeLimit: number;
    procAttributes: number;
    createTime: string;
    createUser: string;
    constructor(options: {
        procDefId?: number;
        procDefName?: string;
        procDesc?: string;
        bizId?: number;
        bizName?: string;
        timeStrategy?: number;
        timeUnitId?: number;
        timeUnitName?: string;
        timeWarn?: number;
        timeLimit?: number;
        procAttributes?: number;
        createTime?: string;
        createUser?: string;
    }) {
        this.procDefId = options.procDefId;
        this.procDefName = options.procDefName;
        this.procDesc = options.procDesc;
        this.bizId = options.bizId;
        this.bizName = options.bizName;
        this.timeStrategy = options.timeStrategy;
        this.timeUnitId = options.timeUnitId;
        this.timeUnitName = options.timeUnitName;
        this.timeWarn = options.timeWarn;
        this.timeLimit = options.timeLimit;
        this.procAttributes = options.procAttributes;
        this.createTime = options.createTime;
        this.createUser = options.createUser;
    }
}
/**环节 */
export class ProcActDef {
    actDefId: number;
    actDefName: string;
    actPropertyId: number;
    actPropertyName: string;
    actDefAttrId: number;
    actDefAttr: string[];
    actTypeId: number;
    actTypeName: string;
    warnTime: number;
    limitTime: number;
    createTime: string
    createUser: string;
    procDefId: number;
    pozTop: number = 0;
    pozLeft: number = 0;
    cssStyle: any = { 'position': 'absolute' };
    cssClass: string = "ffbuilder-node";
    constructor(options: {
        actDefId?: number,
        actDefName?: string,
        actPropertyId?: number,
        actPropertyName?: string,
        actDefAttrId?: number,
        actDefAttr?: string[],
        actTypeId?: number,
        actTypeName?: string,
        warnTime?: number,
        limitTime?: number,
        createUser?: string,
        pozTop?: number,
        pozLeft?: number,
        procDefId?: number
    }) {
        this.actDefId = options.actDefId;
        this.actDefName = options.actDefName;
        this.actPropertyId = options.actPropertyId;
        this.actPropertyName = options.actPropertyName;
        this.actDefAttrId = options.actDefAttrId;
        this.actDefAttr = options.actDefAttr;
        this.actTypeId = options.actTypeId;
        this.actTypeName = options.actTypeName;
        this.warnTime = options.warnTime;
        this.limitTime = options.limitTime;
        this.createUser = options.createUser;
        this.pozTop = options.pozTop;
        this.pozLeft = options.pozLeft;
        this.procDefId = options.procDefId;
        this.refreshStyle();
    }

    refreshStyle() {
        this.cssStyle['top'] = this.pozTop + 'px';
        this.cssStyle['left'] = this.pozLeft + 'px';
    }
}
/**关系线条 */
export class ActTrans {
    from: ProcActDef;
    to: ProcActDef;
    text: string;
    color: string;

    drawer: any;//画笔
    path: any;//当前绘制的类容
    clickCallBack: any;//点击回调
    opposite: boolean;//是否存在相反连接线
    constructor(options: {
        from?: ProcActDef,
        to?: ProcActDef,
        text?: string,
        color?: string,
        drawer?: any,
        path?: any,
        clickCallBack?: any,
        opposite?: boolean
    }) {
        this.from = options.from;
        this.to = options.to;
        this.text = options.text;
        this.color = options.color;
        this.drawer = options.drawer;
        this.path = options.path;
        this.clickCallBack = options.clickCallBack;
        this.opposite = options.opposite;
        this.draw();
    }
    draw() {
        if(null == this.from || null == this.to)return;
        let R = 25;
        //计算起点坐标
        let fromrx = this.from.pozLeft + R;
        let fromry = this.from.pozTop + R;

        let tox = this.to.pozLeft + R;
        let toy = this.to.pozTop + R;

        let varP1x, varP1y, varP2x, varP2y, varMidx, varMidy;

        //算两个点间的距离
        let tpointLong = Math.sqrt(Math.pow(Math.abs(fromrx - tox), 2) + Math.pow(Math.abs(fromry - toy), 2));

        //算出与起点圆相交的交点（varP1x，varP1y），算出与终点圆相交的交点（varP2x，varP2y）
        if (fromry <= toy) {
            varP1y = fromry + R * Math.abs(fromry - toy) / tpointLong;
            varP2y = fromry + (1 - R / tpointLong) * Math.abs(fromry - toy);
        } else {
            varP1y = fromry - R * Math.abs(fromry - toy) / tpointLong;
            varP2y = fromry - (1 - R / tpointLong) * Math.abs(fromry - toy);
        }

        if (fromrx <= tox) {
            varP1x = tox - (1 - R / tpointLong) * Math.abs(fromrx - tox);
            varP2x = tox - R * Math.abs(fromrx - tox) / tpointLong;
        } else {
            varP1x = tox + (1 - R / tpointLong) * Math.abs(fromrx - tox);
            varP2x = tox + R * Math.abs(fromrx - tox) / tpointLong;
        }

        //计算两个的中心点
        varMidx = (varP1x + varP2x) / 2;
        varMidy = (varP1y + varP2y) / 2;
        let that = this;
        if (Math.abs(varP1x - varP2x) < 8) {
            if (!this.opposite) {
                this.path = this.drawer.path('M' + (varP1x - 5) + ' ' + varP1y + ' L' + (varMidx - 5) + ' ' + varMidy + ' L' + (varP2x - 5) + ' ' + varP2y + '');
            } else {
                this.path = this.drawer.path('M' + (varP1x + 5) + ' ' + varP1y + ' L' + (varMidx + 5) + ' ' + varMidy + ' L' + (varP2x + 5) + ' ' + varP2y + '');
            }
        } else {
            if (!this.opposite) {
                this.path = this.drawer.path('M' + varP1x + ' ' + (varP1y - 5) + ' L' + varMidx + ' ' + (varMidy - 5) + ' L' + varP2x + ' ' + (varP2y - 5) + '');
            } else {
                this.path = this.drawer.path('M' + varP1x + ' ' + (varP1y + 5) + ' L' + varMidx + ' ' + (varMidy + 5) + ' L' + varP2x + ' ' + (varP2y + 5) + '');
            }
        }
        this.path.fill('none').stroke({ width: 1 })
        this.path.marker('mid', 24, 50, function (add) {
            add.text(that.text || '转交').click(function(){
                alert('Fuck!');
            });
        });
        this.path.marker('end', 10, 6, function (add) {
            add.path('M0,0 L0,6 L7,3 z')
        });
    }

    plot() {
        if(null == this.from || null == this.to)return;
        //计算起点坐标
        let R = 25;
        let fromrx = this.from.pozLeft + R;
        let fromry = this.from.pozTop + R;

        let tox = this.to.pozLeft + R;
        let toy = this.to.pozTop + R;

        let varP1x, varP1y, varP2x, varP2y, varMidx, varMidy;

        //算两个点间的距离
        let tpointLong = Math.sqrt(Math.pow(Math.abs(fromrx - tox), 2) + Math.pow(Math.abs(fromry - toy), 2));

        //算出与起点圆相交的交点（varP1x，varP1y），算出与终点圆相交的交点（varP2x，varP2y）
        if (fromry <= toy) {
            varP1y = fromry + R * Math.abs(fromry - toy) / tpointLong;
            varP2y = fromry + (1 - R / tpointLong) * Math.abs(fromry - toy);
        } else {
            varP1y = fromry - R * Math.abs(fromry - toy) / tpointLong;
            varP2y = fromry - (1 - R / tpointLong) * Math.abs(fromry - toy);
        }

        if (fromrx <= tox) {
            varP1x = tox - (1 - R / tpointLong) * Math.abs(fromrx - tox);
            varP2x = tox - R * Math.abs(fromrx - tox) / tpointLong;
        } else {
            varP1x = tox + (1 - R / tpointLong) * Math.abs(fromrx - tox);
            varP2x = tox + R * Math.abs(fromrx - tox) / tpointLong;
        }
        varMidx = (varP1x + varP2x) / 2;
        varMidy = (varP1y + varP2y) / 2;

        this.path.remove();
        let that = this;
        if (Math.abs(varP1x - varP2x) < 8) {
            if (!this.opposite) {
                this.path = this.drawer.path('M' + (varP1x - 5) + ' ' + varP1y + ' L' + (varMidx - 5) + ' ' + varMidy + ' L' + (varP2x - 5) + ' ' + varP2y + '');
            } else {
                this.path = this.drawer.path('M' + (varP1x + 5) + ' ' + varP1y + ' L' + (varMidx + 5) + ' ' + varMidy + ' L' + (varP2x + 5) + ' ' + varP2y + '');
            }
        } else {
            if (!this.opposite) {
                this.path = this.drawer.path('M' + varP1x + ' ' + (varP1y - 5) + ' L' + varMidx + ' ' + (varMidy - 5) + ' L' + varP2x + ' ' + (varP2y - 5) + '');
            } else {
                this.path = this.drawer.path('M' + varP1x + ' ' + (varP1y + 5) + ' L' + varMidx + ' ' + (varMidy + 5) + ' L' + varP2x + ' ' + (varP2y + 5) + '');
            }
        }
        this.path.fill('none').stroke({ width: 1 })
        this.path.marker('mid', 24, 50, function (add) {
            add.text(that.text || '转交')
        });
        this.path.marker('end', 10, 6, function (add) {
            add.path('M0,0 L0,6 L7,3 z')
        });
    }
}
/**环节参与者 */
export class ProcPart{
    procDefId: number;
    partId: number;
    partName: string;
    partType: string
    unitId: number;
    unitName: string;
    unitCode: string;
    roleId: number;
    roleName: string;
    humanId: number;
    humanName: string;
    constructor(options: {
        procDefId?: number,
        partId?: number,
        partName?: string,
        partType?: string,
        unitId?: number,
        unitName?: string,
        unitCode?: string,
        roleId?: number,
        roleName?: string,
        humanId?: number,
        humanName?: string
    }) {
        this.procDefId = options.procDefId;
        this.partId = options.partId;
        this.partName = options.partName;
        this.partType = options.partType;
        this.unitId = options.unitId;
        this.unitName = options.unitName;
        this.unitCode = options.unitCode;
        this.roleId = options.roleId;
        this.roleName = options.roleName;
        this.humanId = options.humanId;
        this.humanName = options.humanName;
    }
}